package com.lzh.auto;

import com.lzh.interceptor.TokenWebConfig;
import com.lzh.token.TokenTemplate;
import org.aopalliance.intercept.Interceptor;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@AutoConfiguration(after = TokenAutoConfigure.class)
@ConditionalOnClass(value = {HandlerInterceptor.class, WebMvcConfigurer.class})
@EnableConfigurationProperties(value = {TokenInterceptorProperties.class})
@ConditionalOnProperty(prefix = "token.interceptor",name = "enabled",matchIfMissing = true)
public class TokenInterceptorAutoConfigure {
    @Bean
    public WebMvcConfigurer webMvcConfigurer(TokenInterceptorProperties tokenInterceptorProperties, TokenTemplate tokenTemplate){
        TokenWebConfig tokenWebConfig = new TokenWebConfig(tokenInterceptorProperties,tokenTemplate);
        return tokenWebConfig;
    }
}
